<?php
require_once 'common.php';
require_once 'Student.php';
require_once 'ResultData.php';
require_once 'config.php';


if (isGet()) {
    echo "不得以GET访问";
    exit;
}


$name = trim($_REQUEST['name']);
$sex = trim($_REQUEST['sex']);
$age = trim($_REQUEST['age']);
$edu = trim($_REQUEST['edu']);
$city = trim($_REQUEST['city']);
$no = trim($_REQUEST['no']);

$result = new ResultData();
if ($name == "") {
    $result->code = "404";
    $result->msg = "name不能为空";
    exit(json_encode($result));
}
if ($sex == "") {
    $result->code = "404";
    $result->msg = "sex不能为空";
    exit(json_encode($result));
}
if ($edu == "") {
    $result->code = "404";
    $result->msg = "edu不能为空";
    exit(json_encode($result));
}

$con = mysqli_connect($servername, $username, $password, $database, $port);

if (!$con) {
    $result->code = 404;
    $result->msg = "数据库连接不上";
    exit(json_encode($result));
}

$sql = "INSERT INTO t_student(name, sex, age, edu, city, no) " .
    "VALUES('{$name}',{$sex},{$age},'{$edu}',{$city},'{$no}');";

$con->query($sql);

mysqli_close($con);

exit(json_encode($result));
